{extend name="platform/base" /}
{block name="resources"/}
<style>
    .modal-infp-style {
        width: 90%;
        margin: 10px auto;
    }

    .modal-infp-style table {
        width: 100%;
    }

    .modal-infp-style table tr td {
        border: 1px solid #e6e6e6;
        padding: 10px;
    }

    .panel {
        border: none
    }
</style>
{/block}
{block name="right_tab"}
<li><a class="nscs-table-handle_green" href="{:__URL('PLATFORM_MAIN/Promotion/addMansong')}"><i
        class="fa fa-plus-circle"></i>&nbsp;添加满减满送</a></li>
{/block}
{block name="main"}


<section class="panel panel-default">
    <table class="table table-striped b-light text-sm">
        <colgroup>
            <col width="10%">
            <col width="10%">
            <col width="5%">
            <col width="10%">
            <col width="5%">
            <col width="10%">
            <col width="10%">
            <col width="10%">
            <col width="10%">
            <col width="15%">
        </colgroup>
        <thead>
        <tr>
            <th class="center">店铺id</th>
            <th>商品名称</th>
            <th class="center">团购人数</th>
            <th class="center">创建时间</th>
            <th class="center">开始时间</th>
            <th class="center"> 团购有效期</th>
            <th class="center">状态</th>
            <th class="center">活动对象</th>
            <th class="center">备注</th>
            <th class="center">操作</th>
        </tr>
        </thead>
        <tbody id="list">
        <tr></tr>
        </tbody>
    </table>
    {include file="platform/page" /}
</section>
{/block}
{block name="script"}
{include file="platform/page" /}
<script type="text/javascript">
    $(function () {
        LoadingInfo(1);
    });

    function LoadingInfo(pageIndex) {
        $.ajax({
            type: "post",
            url: "{:__URL('PLATFORM_MAIN/Tuangou/tuangouList')}",
            async: true,
            data: {
                "pageIndex": pageIndex
            },
            success: function (data) {
                console.log(data);
                $("#total_count_num").text(data["total_count"]);
                $("#page_count_num").text(data["page_count"]);
                $("#page_count").val(data["page_count"]);
                $("#pageNumber a").remove();
                var html = '';
                if (data["data"].length > 0) {

                    for (var i = 0; i < data["data"].length; i++) {
                        html += '<tr>';
                        html += '<td>' + data['data'][i]['shop_name'] + '</td>';
                        html += '<td>' + data['data'][i]['goods_name'] + '</td>';
                        html += '<td>' + data['data'][i]['tuangou_num'] + '</td>';
                        html += '<td>' + timeStampTurnTime(data["data"][i]["create_time"]) + '</td>';
                        html += '<td>' + timeStampTurnTime(data["data"][i]["time_open"]) + '</td>';
                        html += '<td class="center"> ' + data['data'][i]['tuangou_time'] + '小时</td>';

                        if (data['data'][i]['is_open'] == 0) {
                            html += '<td class="center">待审核</td>';
                        } else if (data['data'][i]['is_open'] == 1) {
                            html += '<td class="center">已通过</td>';
                        } else if (data['data'][i]['is_open'] == 2) {
                            html += '<td class="center">已拒绝</td>';
                        }

                        if (data['data'][i]['goods_type_crowd'] == 1) {
                            html += '<td class="center">全部</td>';
                        } else if (data['data'][i]['goods_type_crowd'] == 2) {
                            html += '<td class="center">企业内部活动</td>';
                        } else if (data['data'][i]['goods_type_crowd'] == 3) {
                            html += '<td class="center">外部活动</td>';
                        }
                        html += '<td>' + data['data'][i]['remark'] + '</td>';

                        html += '<td class="center">';
                        if (data['data'][i]['is_open'] == 0) {
                            html += '<a href="javascript:;" onclick="setStatusType(' + data["data"][i]["tuangou_id"] + ',' + data["data"][i]["goods_id"] + ',1,' + data["data"][i]["goods_type_crowd"] + ');">通过</a>&nbsp;&nbsp;&nbsp;'
                                + '<a href="javascript:;" onclick="setStatusType(' + data["data"][i]["tuangou_id"] + ',' + data["data"][i]["goods_id"] + ',2,' + data["data"][i]["goods_type_crowd"] + ');">拒绝</a>&nbsp;&nbsp;&nbsp;';
                        }
                        if (data['data'][i]['is_open'] == 1) {
                            html += '<a href="javascript:;" onclick="setStatusType(' + data["data"][i]["tuangou_id"] + ',' + data["data"][i]["goods_id"] + ',3,' + data["data"][i]["goods_type_crowd"] + ');">关闭</a>&nbsp;&nbsp;&nbsp;';
                        }

                        html += '<a href="' + __URL('PLATFORM_MAIN/goods/goodsinfo?goodsid=' + data["data"][i]["goods_id"]) + '">查看</a></td>';
                        html += '</tr>';
                    }
                } else {
                    html += '<tr align="center"><td colspan="8" style="text-align:center;">暂无限时折扣活动数据记录</td></tr>';
                }
                $("#list").html(html);
                var totalpage = $("#page_count").val();
                if (totalpage == 1) {
                    changeClass("all");
                }
                var $html = pagenumShow(jumpNumber, totalpage, {$pageshow})
                $("#pageNumber").append($html);
            }
        });
    }

    function searchData() {
        LoadingInfo(1);
    }


    function setStatusType(tuangou_id, goods_id, is_open,goods_type_crowd) {
        $.ajax({
            type: "post",
            url: "{:__URL('PLATFORM_MAIN/Tuangou/tuangouDispose')}",
            async: true,
            data: {
                "tuangou_id": tuangou_id, 'goods_id': goods_id, 'is_open': is_open, 'goods_type_crowd': goods_type_crowd
            },
            success: function (data) {
                console.log(data);
                if (data==true) {
                    showMessage('success', '操作成功');
                }else{
                    showMessage('error', "操作失败");
                }
                LoadingInfo(1);
            }
        })
    }


    //关闭满减送
    function closeMansong(discount_id) {
        $.ajax({
            type: "post",
            url: "{:__URL('PLATFORM_MAIN/Promotion/closeDiscount')}",
            async: true,
            data: {
                "discount_id": discount_id
            },
            success: function (data) {
                if (data["code"] > 0) {
                    showMessage('success', data["message"], "{:__URL('PLATFORM_MAIN/Promotion/getdiscountlist')}");
                } else {
                    showMessage('error', data["message"]);
                }
            }
        })
    }

    //删除满减送
    function delMansong(discount_id) {
        $.ajax({
            type: "post",
            url: "{:__URL('PLATFORM_MAIN/Promotion/delDiscount')}",
            async: true,
            data: {
                "discount_id": discount_id
            },
            success: function (data) {
                if (data["code"] > 0) {
                    showMessage('success', data["message"], "{:__URL('PLATFORM_MAIN/Promotion/getdiscountlist')}");
                } else {
                    showMessage('error', data["message"]);
                }
            }
        })
    }

    /* function mansongInfo(mansong_id){
        $("#mansongInfo").modal("show");
        $.ajax({
            type:"get",
            url : "{:__URL('PLATFORM_MAIN/Promotion/getMansongDetail')}",
            async : true,
            data : {
                "mansong_id" : mansong_id
            },
            success : function(data) {
                $("#gift_name").text(data["mansong_name"]);
                $("#time").text(data['start_time']+' 至 '+data['end_time']);
                switch(data['status']){
                    case 0:
                        var status_name = '未发布';
                         break;
                    case 1:
                        var status_name = '正常';
                          break;
                    case 3:
                        var status_name = '已关闭';
                        break;
                    case 4:
                        var status_name = '已结束';
                        break;
                }
                $("#status").text(status_name);
                var rule_html = '';
                for(var i=0;i<data['rule'].length;i++){
                    rule_html += '<tr class="rule">';
                    rule_html += '<td>'+data['rule'][i]['price']+'</td>';
                    rule_html += '<td>'+data['rule'][i]['discount']+'</td>';
                    rule_html += '<td>'+data['rule'][i]['free_shipping_name']+'</td>';
                    rule_html += '<td>'+data['rule'][i]['give_point']+'</td>';
                    rule_html += '<td>'+data['rule'][i]['coupon_name']+'</td>';
                    rule_html += '<td>'+data['rule'][i]['gift_name']+'</td>';
                    rule_html += '</tr>';
                }
                $("#mansongInfo table tr.rule").remove();
                $("#rule").after(rule_html);
                var goods_list = '';
                for(var i=0;i<data['goods_list'].length;i++){
                    goods_list += '<tr class="goods_list">';
                    goods_list += '<td><img src="__ROOT__/'+data['goods_list'][i]['picture']['pic_cover_micro']+'"></td>';
                    goods_list += '<td colspan="5">'+data['goods_list'][i]['goods_name']+'</td>';
                    goods_list += '</tr>';
                }
                $("#mansongInfo table tr.goods_list").remove();
                $("#goods_list").after(goods_list);
            }
        })
    } */
</script>
<!-- 模态框（Modal） -->

{/block}